<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link type="text/css" rel="stylesheet" href="./lib/codemirror.css" />
  <link type="text/css" rel="stylesheet" href="./theme/eclipse-ext.css" />
  <link type="text/css" rel="stylesheet" href="./addon/hint/show-hint.css" />
  <script type="text/javascript" src="./lib/codemirror.js"></script>
  <script type="text/javascript" src="./mode/javascript/javascript.js"></script>
  <script type="text/javascript" src="./addon/hint/show-hint.js"></script>
  <script type="text/javascript" src="./addon/hint/javascript-hint.js"></script>
  <style>
    .CodeMirror {
      border: 1px solid red;
    }
  </style>
</head>

<body>
  <h2>Autocomplete Demo</h2>
  <textarea id="code" name="code"></textarea>

  <script>
    var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
      lineNumbers: true,
      extraKeys: { "Ctrl-Q": "autocomplete" },  //避免热键冲突  
      mode: { name: "javascript", globalVars: true }
    });

    // editor.on('change', function () {
    //   editor.showHint();  //满足自动触发自动联想功能
    // });
  </script>
</body>

</html>